﻿using Architecture.API.Application.TraceabilityCommand.TraceabilitiesCommand;
using MediatR;
using Traceability.Domain.Service.TraceabilitiesServices;

namespace Architecture.API.Application.TraceabilityCommandHandler.TraceabilitiesCommandHandler
{
    public class DeletedTraceabilitiesCommandHandler : IRequestHandler<DeletedTraceabilitiesCommand, int>
    {
        /// <summary>
        /// 免疫服务
        /// </summary>
        protected readonly ITraceabilitiesService traceabilitiesService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="traceabilitiesService">免疫服务</param>
        public DeletedTraceabilitiesCommandHandler(ITraceabilitiesService traceabilitiesService)
        {
            this.traceabilitiesService = traceabilitiesService;
        }

        public async Task<int> Handle(DeletedTraceabilitiesCommand request, CancellationToken cancellationToken)
        {
            return await traceabilitiesService.DeleteTraceabilities(request.traceabilityId, request.userName);
        }
    }
}
